package com.ruoyi.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.purchase.domain.InspectionScheme;
import com.ruoyi.purchase.service.IInspectionSchemeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检验方案Controller
 * 
 * @author ruoyi
 * @date 2025-10-31
 */
@RestController
@RequestMapping("/purchase/scheme")
public class InspectionSchemeController extends BaseController
{
    @Autowired
    private IInspectionSchemeService inspectionSchemeService;

    /**
     * 查询检验方案列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:scheme:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionScheme inspectionScheme)
    {
        startPage();
        List<InspectionScheme> list = inspectionSchemeService.selectInspectionSchemeList(inspectionScheme);
        return getDataTable(list);
    }

    /**
     * 导出检验方案列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:scheme:export')")
    @Log(title = "检验方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionScheme inspectionScheme)
    {
        List<InspectionScheme> list = inspectionSchemeService.selectInspectionSchemeList(inspectionScheme);
        ExcelUtil<InspectionScheme> util = new ExcelUtil<InspectionScheme>(InspectionScheme.class);
        util.exportExcel(response, list, "检验方案数据");
    }

    /**
     * 获取检验方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:scheme:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionSchemeService.selectInspectionSchemeById(id));
    }

    /**
     * 新增检验方案
     */
    @PreAuthorize("@ss.hasPermi('purchase:scheme:add')")
    @Log(title = "检验方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionScheme inspectionScheme)
    {
        return toAjax(inspectionSchemeService.insertInspectionScheme(inspectionScheme));
    }

    /**
     * 修改检验方案
     */
    @PreAuthorize("@ss.hasPermi('purchase:scheme:edit')")
    @Log(title = "检验方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionScheme inspectionScheme)
    {
        return toAjax(inspectionSchemeService.updateInspectionScheme(inspectionScheme));
    }

    /**
     * 删除检验方案
     */
    @PreAuthorize("@ss.hasPermi('purchase:scheme:remove')")
    @Log(title = "检验方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionSchemeService.deleteInspectionSchemeByIds(ids));
    }
}
